//
//  JoinQuizMoreView.m
//  WanCaiC8
//
//  Created by tangang on 2018/3/19.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "JoinQuizMoreView.h"
#import "JoinQuizMoreCell.h"
@interface JoinQuizMoreView()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,strong) UITableView  *tableView;
@property (nonatomic ,strong) NSArray    *dataArr;
@end

@implementation JoinQuizMoreView{
    LotteryNumType lotteryNumType;
}

- (instancetype)init{
    if (self=[super init]) {
        WS(weakSelf);
        self.backgroundColor=[UIColor colorWithWhite:0 alpha:.2];
        UIView *bgView=[[UIView alloc]init];
        bgView.backgroundColor=DEFAULTBGCOLOR;
        [self addSubview:bgView];
        [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(weakSelf);
            make.height.mas_equalTo(@30);
        }];
        
        QXLable *labPeriod =[[QXLable alloc]init];
        labPeriod.text=@"期次";
        labPeriod.textAlignment=NSTextAlignmentCenter;
        [bgView addSubview:labPeriod];
        [labPeriod mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.equalTo(bgView);
            make.width.mas_equalTo(@100);
        }];
        
        QXLable *labNum=[[QXLable alloc]init];
        labNum.textAlignment=NSTextAlignmentCenter;
        labNum.text=@"开奖号码";
        [bgView addSubview:labNum];
        [labNum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.top.bottom.equalTo(bgView);
            make.width.mas_equalTo(@300);
        }];
        
        UIView *line=[[UIView alloc]init];
        line.backgroundColor=DEFAULTBGCOLOR;
        [bgView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(bgView);
            make.height.mas_equalTo(@.7);
        }];
    }
    return self;
}

- (void)setData:(NSArray *)data andType:(LotteryNumType)type{
    lotteryNumType=type;
    _dataArr=data;
    [self.tableView reloadData];
}

- (void)onclickMore{
    if (self.moreBlock) {
        self.moreBlock();
    }
}

#pragma mark -- UITableViewDelegate ,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count>5?5:self.dataArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JoinQuizMoreCell *cell=[tableView dequeueReusableCellWithIdentifier:@"JoinQuizMoreCell" forIndexPath:indexPath];
    [cell setData:self.dataArr[indexPath.row] andType:lotteryNumType];
    return cell;
}

#pragma mark -- 懒加载
- (UITableView *)tableView{
    if (!_tableView) {
        WS(weakSelf);
        _tableView=[[UITableView alloc]init];
        _tableView.dataSource=self;
        _tableView.delegate=self;
        _tableView.backgroundColor=DEFAULTBGCOLOR;
        [_tableView registerClass:[JoinQuizMoreCell class] forCellReuseIdentifier:@"JoinQuizMoreCell"];
        _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        UIButton  *moreBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
        moreBtn.backgroundColor=DEFAULTBGCOLOR;
        [moreBtn setTitle:@"点击查看更多开奖历史>>" forState:UIControlStateNormal];
        [moreBtn addTarget:self action:@selector(onclickMore) forControlEvents:UIControlEventTouchUpInside];
        [moreBtn.titleLabel setFont:[UIFont systemFontOfSize:14]];
        [moreBtn setTitleColor:NAVCOLOR forState:UIControlStateNormal];
        _tableView.tableFooterView=moreBtn;
        [self addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(weakSelf);
            make.top.equalTo(weakSelf).with.offset(30);
            make.height.mas_equalTo(@215);
        }];
    }
    return _tableView;
}
@end
